<?php

namespace Transaccion\Controller;

use Transaccion\Controller\GenericController;
use Componentes\Controller\UtilsArrayController;

class SemestreController extends GenericController {

    public function __construct() {
        
    }

    public function get($id) {
        /*
         * selecciona todo lo que corresponde al id de SEmestre         
         * Ej: http://localhost/UptaebBackend/public/transaccion/semestre/9
         * Rsp: {"success":true,"data":[{"id":"9","_organizacionSeccion":null,
         * "_condicionMateria":null,"_datosAcademicos":null}],"total":1,
         * "mensaje":null} 
         */
        
        $id = $this->params()->fromRoute('id'); 
        $output = $this->getSemestreService()->getRegistro($id);
        return $this->convertirArrayAJson($output);
    }

    /**
     * Return list of resources
     * @return mixed
     */
  public function getList($id = 1, $param1 = 1, $param2 = 1, $param3 = 1) {
        $id = $this->params()->fromRoute('id');
        $param1 = $this->params()->fromRoute('param1');
        $data = null;
        $mensaje = "Defaul";
        switch ($id) {
            case (0):
                /*
                 * Datos del datosAcademicos sin los objetos foraneos (con el id del grupo)
                 * Ej: http://localhost/UptaebBackend/public/transaccion/Semestre/0/9
                 * Rsp: {"success":true,"data":[{"id":"9",
                 * "_organizacionSeccion":"112","_condicionMateria":"1",
                 * "_datosAcademicos":"95230"}],"total":1,"mensaje":null}
                 */
                $id = $this->params()->fromRoute('param1');
                $output = $this->getSemestreService()->getRegistro($id);
                break; 
               case (1):
                /*
                 * Datos del datosAcademicos sin los objetos foraneos (con el id del grupo)
                 * Ej: http://localhost/UptaebBackend/public/transaccion/Semestre/0/9
                 * Rsp: {"success":true,"data":[{"id":"9",
                 * "_organizacionSeccion":"112","_condicionMateria":"1",
                 * "_datosAcademicos":"95230"}],"total":1,"mensaje":null}
                 */
                $id= $this->params()->fromRoute('param1');
                $output = $this->getSemestreService()->getSemestreSegunIdDatosAcademicos($id);
                break;    
            default:
                return $param1;
        }
        return $this->convertirArrayAJson($output);
    }
   
     public function delete($id) {         
        $id = $this->params()->fromRoute('id');     
        $result = $this->getSemestreService()->deleteSemestreSegunId($id);
        $response = $this->getResponseWithHeader();
        $response->setContent($result);
        return $response;
    }
   
        /**
     * Create a new resource
     * @param  mixed $data
     * @return mixed
     * Ruta: http://localhost/UptaebBackend/public/seguridad/bitacora/@idUsuario/@idNodo/@detalle/@otro
     * Ej: http://localhost/UptaebBackend/public/seguridad/bitacora/1/1/Click_boton_de_inicio_de_sesion/null
     */
    public function create($data) {
        $id = $this->params()->fromRoute('id');
        $organizacionSeccion = $this->params()->fromRoute('param1');
        $condicionMateria = $this->params()->fromRoute('param2');
        $datosAcademicos = $this->params()->fromRoute('param3');
        $result = $this->getSemestreService()->createRegistro($organizacionSeccion, $condicionMateria, $datosAcademicos);
        $response = $this->getResponseWithHeader();
        $response->setContent($result);
        return $response;
    }
}